<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />

	<title>Class: S3aps::Sync</title>

	<link rel="stylesheet" href="../rdoc.css" type="text/css" media="screen" />

	<script src="../js/jquery.js" type="text/javascript"
		charset="utf-8"></script>
	<script src="../js/thickbox-compressed.js" type="text/javascript"
		charset="utf-8"></script>
	<script src="../js/quicksearch.js" type="text/javascript"
		charset="utf-8"></script>
	<script src="../js/darkfish.js" type="text/javascript"
		charset="utf-8"></script>

</head>
<body class="class">

	<div id="metadata">
		<div id="home-metadata">
			<div id="home-section" class="section">
        <h3 class="section-header">
          <a href="../index.html">Home</a>
          <a href="../index.html#classes">Classes</a>
          <a href="../index.html#methods">Methods</a>
        </h3>
			</div>
		</div>

		<div id="file-metadata">
			<div id="file-list-section" class="section">
				<h3 class="section-header">In Files</h3>
				<div class="section-body">
					<ul>
					
						<li><a href="../lib/s3aps/sync_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
							class="thickbox" title="lib/s3aps/sync.rb">lib/s3aps/sync.rb</a></li>
					
					</ul>
				</div>
			</div>

			
		</div>

		<div id="class-metadata">

			<!-- Parent Class -->
			
			<div id="parent-class-section" class="section">
				<h3 class="section-header">Parent</h3>
				
				<p class="link">Object</p>
				
			</div>
			

			<!-- Namespace Contents -->
			

			<!-- Method Quickref -->
			
			<div id="method-list-section" class="section">
				<h3 class="section-header">Methods</h3>
				<ul class="link-list">
					
					<li><a href="#method-c-new">::new</a></li>
					
					<li><a href="#method-i-list">#list</a></li>
					
					<li><a href="#method-i-pull">#pull</a></li>
					
					<li><a href="#method-i-push">#push</a></li>
					
				</ul>
			</div>
			

			<!-- Included Modules -->
			
		</div>

		<div id="project-metadata">
			
			

			<div id="classindex-section" class="section project-section">
				<h3 class="section-header">Class Index
					<span class="search-toggle"><img src="../images/find.png"
						height="16" width="16" alt="[+]"
						title="show/hide quicksearch" /></span></h3>
				<form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
				<fieldset>
					<legend>Quicksearch</legend>
					<input type="text" name="quicksearch" value=""
						class="quicksearch-field" />
				</fieldset>
				</form>

				<ul class="link-list">
				
					<li><a href="../S3aps/FileAdapter.html">S3aps::FileAdapter</a></li>
				
					<li><a href="../S3aps/Runner.html">S3aps::Runner</a></li>
				
					<li><a href="../S3aps/S3Adapter.html">S3aps::S3Adapter</a></li>
				
					<li><a href="../S3aps/Sync.html">S3aps::Sync</a></li>
				
				</ul>
				<div id="no-class-search-results" style="display: none;">No matching classes.</div>
			</div>

			
		</div>
	</div>

	<div id="documentation">
		<h1 class="class">S3aps::Sync</h1>

		<div id="description">
			<p>
The controller for everything else. 
</p>

		</div>

		<!-- Constants -->
		

		<!-- Attributes -->
		

		<!-- Methods -->
		
		<div id="public-class-method-details" class="method-section section">
			<h3 class="section-header">Public Class Methods</h3>

		
			<div id="new-method" class="method-detail ">
				<a name="method-c-new"></a>

				<div class="method-heading">
				
					<span class="method-name">new</span><span
						class="method-args">(options = {})</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					
					

					
					<div class="method-source-code"
						id="new-source">
<pre>
    <span class="ruby-comment cmt"># File lib/s3aps/sync.rb, line 22</span>
22:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">options</span> = {})
23:       <span class="ruby-identifier">options</span> = <span class="ruby-constant">S3aps</span><span class="ruby-operator">::</span><span class="ruby-identifier">symbolize_keys</span>(<span class="ruby-identifier">options</span>)
24:       <span class="ruby-identifier">s3_file</span> = [<span class="ruby-identifier">options</span>[<span class="ruby-value">:config</span>], <span class="ruby-value str">&quot;s3.yml&quot;</span>, <span class="ruby-value str">&quot;config/s3.yml&quot;</span>].<span class="ruby-identifier">detect</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span> <span class="ruby-identifier">f</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">file?</span>(<span class="ruby-identifier">f</span>) }
25:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">s3_file</span>
26:         <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Configuring S3 from #{s3_file}&quot;</span>
27:         <span class="ruby-identifier">yaml_options</span> = <span class="ruby-constant">S3aps</span><span class="ruby-operator">::</span><span class="ruby-identifier">symbolize_keys</span> <span class="ruby-constant">YAML</span>.<span class="ruby-identifier">load_file</span>(<span class="ruby-identifier">s3_file</span>)
28:         <span class="ruby-identifier">env</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value">:env</span>]
29:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">env</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">yaml_options</span>[<span class="ruby-identifier">env</span>.<span class="ruby-identifier">to_sym</span>]
30:           <span class="ruby-identifier">yaml_options</span> = <span class="ruby-constant">S3aps</span><span class="ruby-operator">::</span><span class="ruby-identifier">symbolize_keys</span> <span class="ruby-identifier">yaml_options</span>[<span class="ruby-identifier">env</span>.<span class="ruby-identifier">to_sym</span>]
31:           <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Using #{env} environment&quot;</span>
32:         <span class="ruby-keyword kw">end</span>
33:         <span class="ruby-comment cmt"># Support for alias: access_key_id = key </span>
34:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">yaml_options</span>[<span class="ruby-value">:access_key_id</span>]
35:           <span class="ruby-identifier">yaml_options</span>[<span class="ruby-value">:key</span>] <span class="ruby-operator">||=</span> <span class="ruby-identifier">yaml_options</span>[<span class="ruby-value">:access_key_id</span>]
36:           <span class="ruby-identifier">yaml_options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:access_key_id</span>)
37:         <span class="ruby-keyword kw">end</span>
38:         <span class="ruby-comment cmt"># Support for alias: secret_access_key = secret </span>
39:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">yaml_options</span>[<span class="ruby-value">:secret_access_key</span>]
40:           <span class="ruby-identifier">yaml_options</span>[<span class="ruby-value">:secret</span>] <span class="ruby-operator">||=</span> <span class="ruby-identifier">yaml_options</span>[<span class="ruby-value">:secret_access_key</span>]
41:           <span class="ruby-identifier">yaml_options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:secret_access_key</span>)
42:         <span class="ruby-keyword kw">end</span>
43:         <span class="ruby-identifier">options</span>.<span class="ruby-identifier">merge!</span>(<span class="ruby-identifier">yaml_options</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">k</span>,<span class="ruby-identifier">o</span>,<span class="ruby-identifier">n</span><span class="ruby-operator">|</span> <span class="ruby-identifier">o</span> }
44:       <span class="ruby-keyword kw">end</span>
45:       <span class="ruby-ivar">@s3_adapter</span> = <span class="ruby-constant">S3aps</span><span class="ruby-operator">::</span><span class="ruby-constant">S3Adapter</span>.<span class="ruby-identifier">new</span> <span class="ruby-identifier">options</span>
46:       <span class="ruby-ivar">@file_adapter</span> = <span class="ruby-constant">S3aps</span><span class="ruby-operator">::</span><span class="ruby-constant">FileAdapter</span>.<span class="ruby-identifier">new</span> <span class="ruby-identifier">options</span>
47:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
		</div>
	
		<div id="public-instance-method-details" class="method-section section">
			<h3 class="section-header">Public Instance Methods</h3>

		
			<div id="list-method" class="method-detail ">
				<a name="method-i-list"></a>

				<div class="method-heading">
				
					<span class="method-name">list</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Merge the local and remote lists into one and indicate whether each item is
local, remote or both
</p>
					

					
					<div class="method-source-code"
						id="list-source">
<pre>
    <span class="ruby-comment cmt"># File lib/s3aps/sync.rb, line 51</span>
51:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">list</span>
52:       <span class="ruby-identifier">local</span> = <span class="ruby-ivar">@file_adapter</span>.<span class="ruby-identifier">list</span> 
53:       <span class="ruby-identifier">remote</span> = <span class="ruby-ivar">@s3_adapter</span>.<span class="ruby-identifier">list</span>.<span class="ruby-identifier">map</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span> <span class="ruby-identifier">i</span>[<span class="ruby-value">:key</span>]}
54:       <span class="ruby-identifier">all</span> = (<span class="ruby-identifier">local</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">remote</span>).<span class="ruby-identifier">uniq</span>.<span class="ruby-identifier">sort</span>
55:       <span class="ruby-identifier">all</span>.<span class="ruby-identifier">map</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">path</span><span class="ruby-operator">|</span>
56:         [
57:           <span class="ruby-identifier">local</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">path</span>) <span class="ruby-operator">?</span> <span class="ruby-value str">&quot;L&quot;</span> <span class="ruby-operator">:</span> <span class="ruby-value str">&quot; &quot;</span>,
58:           <span class="ruby-identifier">remote</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">path</span>) <span class="ruby-operator">?</span> <span class="ruby-value str">&quot;R&quot;</span> <span class="ruby-operator">:</span> <span class="ruby-value str">&quot; &quot;</span>,
59:           <span class="ruby-identifier">path</span>
60:         ]
61:       <span class="ruby-keyword kw">end</span>
62:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="pull-method" class="method-detail ">
				<a name="method-i-pull"></a>

				<div class="method-heading">
				
					<span class="method-name">pull</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Get all the remote files and write them out locally, if they don&#8217;t
already exist. For simplicity, we assume that if a file of the same name
already exists then it is the same as the remote one. 
</p>
					

					
					<div class="method-source-code"
						id="pull-source">
<pre>
    <span class="ruby-comment cmt"># File lib/s3aps/sync.rb, line 67</span>
67:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">pull</span>
68:       <span class="ruby-identifier">check_list</span> = <span class="ruby-identifier">local_list</span>
69:       <span class="ruby-identifier">count</span> = <span class="ruby-value">0</span>
70:       <span class="ruby-identifier">total</span> = <span class="ruby-value">0</span>
71:                 <span class="ruby-ivar">@s3_adapter</span>.<span class="ruby-identifier">list</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">o</span><span class="ruby-operator">|</span>
72:         <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">check_list</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">o</span>[<span class="ruby-value">:key</span>])
73:           <span class="ruby-identifier">$stdout</span>.<span class="ruby-identifier">print</span> <span class="ruby-value str">&quot;*&quot;</span>
74:                     <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@file_adapter</span>.<span class="ruby-identifier">write</span>(<span class="ruby-identifier">o</span>[<span class="ruby-value">:key</span>], <span class="ruby-ivar">@s3_adapter</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">o</span>[<span class="ruby-value">:key</span>]), <span class="ruby-identifier">o</span>[<span class="ruby-value">:etag</span>])
75:                       <span class="ruby-identifier">count</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
76:                       <span class="ruby-keyword kw">end</span>
77:                     <span class="ruby-keyword kw">else</span>
78:           <span class="ruby-identifier">$stdout</span>.<span class="ruby-identifier">print</span> <span class="ruby-value str">&quot;.&quot;</span>
79:                     <span class="ruby-keyword kw">end</span>
80:         <span class="ruby-identifier">$stdout</span>.<span class="ruby-identifier">flush</span>
81:         <span class="ruby-identifier">total</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
82:                   <span class="ruby-keyword kw">end</span>
83:     [<span class="ruby-identifier">count</span>, <span class="ruby-identifier">total</span>]
84:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="push-method" class="method-detail ">
				<a name="method-i-push"></a>

				<div class="method-heading">
				
					<span class="method-name">push</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Get all the local files, recursively, and write them to S3, if they
don&#8217;t already exist. For simplicity, we assume that if a file of the
same name already exists then it is the same as the local one. 
</p>
					

					
					<div class="method-source-code"
						id="push-source">
<pre>
     <span class="ruby-comment cmt"># File lib/s3aps/sync.rb, line 89</span>
 89:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">push</span>
 90:       <span class="ruby-identifier">check_list</span> = <span class="ruby-identifier">remote_list</span>
 91:       <span class="ruby-identifier">count</span> = <span class="ruby-value">0</span>
 92:       <span class="ruby-identifier">total</span> = <span class="ruby-value">0</span>
 93:       <span class="ruby-ivar">@file_adapter</span>.<span class="ruby-identifier">list</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">path</span><span class="ruby-operator">|</span>
 94:         <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">check_list</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">path</span>)
 95:           <span class="ruby-identifier">$stdout</span>.<span class="ruby-identifier">print</span> <span class="ruby-value str">&quot;*&quot;</span>
 96:           <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@s3_adapter</span>.<span class="ruby-identifier">write</span>(<span class="ruby-identifier">path</span>, <span class="ruby-ivar">@file_adapter</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">path</span>))
 97:             <span class="ruby-identifier">count</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
 98:           <span class="ruby-keyword kw">end</span>
 99:                     <span class="ruby-keyword kw">else</span>
100:           <span class="ruby-identifier">$stdout</span>.<span class="ruby-identifier">print</span> <span class="ruby-value str">&quot;.&quot;</span>
101:         <span class="ruby-keyword kw">end</span>
102:         <span class="ruby-identifier">$stdout</span>.<span class="ruby-identifier">flush</span>
103:         <span class="ruby-identifier">total</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
104:       <span class="ruby-keyword kw">end</span>
105:       [<span class="ruby-identifier">count</span>, <span class="ruby-identifier">total</span>]
106:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
		</div>
	

	</div>


	<div id="rdoc-debugging-section-dump" class="debugging-section">
	
		<p>Disabled; run with --debug to generate this.</p>
	
	</div>

	<div id="validator-badges">
		<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
		<p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
			Rdoc Generator</a> 1.1.6</small>.</p>
	</div>

</body>
</html>

